const App = {
    mixins: [Query],//配置文件，路径/utils/mixins.js
    data() {
        return {
            photo,
            page: {
                activeName: 'first',
                value1: '',
                PageNumber: 1, //页码
                RowAmount: 10,
                Condition: window.btoa(unescape(encodeURIComponent("%%"))),
                ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND comments.Parent_SerialNumber = ''")))
            },
            str1: '',
            str: '',
        }
    },
    mounted() {

    },
    methods: {
        check() {
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%")));
            this.postgetList(this.page);
        },
        handleClick() {
            if (this.page.activeName == 'first') {
                this.str1 = '';
            } else if (this.page.activeName == 'second') {
                this.str1 = "\r\nAND news.Row_Status = '2'";
            } else if (this.page.activeName == 'third') {
                this.str1 = "\r\nAND news.Row_Status = '0'";
            } else if (this.page.activeName == 'fourth') {
                this.str1 = "\r\nAND news.Row_Status = '3'";
            }
            this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent(this.str + this.str1)));
            this.postgetList(this.page)
        },
        //树的点击筛选事件
        handleNodeClick(data, node) {
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%" + data.News_Category_SerialNumber + "%")));
            this.postgetList(this.page);
        },
        postgetList(page) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                method: "post",
                data: {
                    Model_Url: this.relativePath,
                    Condition: page.Condition,
                    PaginationNumber: page.PageNumber,
                    ...page,
                },
                success: (res) => {
                    that.Total = res.TotalRows;//总数量
                    that.loading = false;
                    res.Rows.forEach(item => {
                        if (item.total > 0) {
                            item.children = [];
                            item.hasChildren = true;
                        }
                    });
                    that.Tabletdata = res.Rows;
                    submitSave({
                        Add: {
                            base_operation_log: [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main: JSON.stringify(deepClone({
                                    Data: res.Rows,
                                    Param: {
                                        Model_Url: this.relativePath,
                                        Condition: page.Condition,
                                        PaginationNumber: page.PageNumber,
                                        ...page,
                                        ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND comments.Parent_SerialNumber <> ''")))
                                    }
                                })),
                                Operation_Interface: "generalPaginationQueryBySQLSerialNumber",
                                Operation_IP: getIpAddress()
                            }]
                        }
                    })
                    // $.ajax({
                    //     headers: requestHeaders("JSON"),
                    //     url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                    //     method: "post",
                    //     data: JSON.stringify({
                    //         Data: {
                    //             Add: {
                    //                 base_operation_log: [{
                    //                     Operation_Type: '0',
                    //                     Operation_Path: this.relativePath,
                    //                     Operation_Main: JSON.stringify(deepClone({
                    //                         Data: res.Rows,
                    //                         Param: {
                    //                             Model_Url: this.relativePath,
                    //                             Condition: page.Condition,
                    //                             PaginationNumber: page.PageNumber,
                    //                             ...page,
                    //                             ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND comments.Parent_SerialNumber <> ''")))
                    //                         }
                    //                     })),
                    //                     Operation_Interface: "generalPaginationQueryBySQLSerialNumber",
                    //                     Operation_IP: getIpAddress()
                    //                 }]
                    //             }
                    //         },
                    //     }),
                    //     complete: (XMLHttpRequest) => {
                    //         requestPretreatment(XMLHttpRequest)
                    //     }
                    // });
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                }
            });
        },
        load(tree, treeNode, resolve) {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
                method: "post",
                data: {
                    Model_Url: this.relativePath,
                    Condition: window.btoa(unescape(encodeURIComponent("%%"))),
                    ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND comments.Parent_SerialNumber='" + tree.Comment_SerialNumber + "'")))
                },
                success: (data) => {
                    data.forEach(item => {
                        if (item.total > 0) {
                            item.children = [];
                            item.hasChildren = true;

                        }
                        item.isEdit = true;
                    });
                    submitSave({
                        Add: {
                            base_operation_log: [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main: JSON.stringify(deepClone({
                                    Data: data,
                                    Param: {
                                        Model_Url: this.relativePath,
                                        Condition: window.btoa(unescape(encodeURIComponent("%%"))),
                                        ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND comments.Parent_SerialNumber='" + tree.Comment_SerialNumber + "'")))
                                    }
                                })),
                                Operation_Interface: "generalQueryBySQLSerialNumber",
                                Operation_IP: getIpAddress()
                            }]
                        }
                    })
                    // $.ajax({
                    //     headers: requestHeaders("JSON"),
                    //     url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                    //     method: "post",
                    //     data: JSON.stringify({
                    //         Data: {
                    //             Add: {
                    //                 base_operation_log: [{
                    //                     Operation_Type: '0',
                    //                     Operation_Path: this.relativePath,
                    //                     Operation_Main: JSON.stringify(deepClone({
                    //                         Data: data,
                    //                         Param: {
                    //                             Model_Url: this.relativePath,
                    //                             Condition: window.btoa(unescape(encodeURIComponent("%%"))),
                    //                             ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND comments.Parent_SerialNumber='" + tree.Comment_SerialNumber + "'")))
                    //                         }
                    //                     })),
                    //                     Operation_Interface: "generalQueryBySQLSerialNumber",
                    //                     Operation_IP: getIpAddress()
                    //                 }]
                    //             }
                    //         },
                    //     }),
                    //     complete: (XMLHttpRequest) => {
                    //         requestPretreatment(XMLHttpRequest)
                    //     }
                    // });
                    resolve(data);
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest)
                }
            });
        },
        handleShow(row){
            window.location.href = './show.html?action=Add&Comment_SerialNumber=' + row.Comment_SerialNumber + "&Comment_Object_SerialNumber=" + row.Comment_Object_SerialNumber
        },
        handle1(data, is) {
            this.$confirm('该操作将' + (is == '0' ? '审核通过' : is == '2' ? '重新审核' : is == '3' ? '审核拒绝' : '') + '此条数据,是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                let { TableName, primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                    method: "post",
                    data: {
                        Data: TableName,
                        Condition: primary_key + "='" + data[primary_key] + "'"
                    },
                    success: (res) => {
                        if (res.length == 1) {
                            res[0].Row_Status = is;
                            let lJSONObject_DataSet = new Object();
                            let lJSONObject_Table = new Object();
                            lJSONObject_Table[TableName] = res;
                            lJSONObject_DataSet['Modify'] = lJSONObject_Table;
                            let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                            if (!lJSONObject_DataSet['Add']) {
                                lJSONObject_DataSet['Add'] = new Object();
                            }
                            lJSONObject_DataSet['Add']['base_operation_log'] = [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main,
                                Operation_Interface: "generalSave",
                                Operation_IP: getIpAddress()
                            }]
                            submitSave(lJSONObject_DataSet,(res)=>{
                                if (res.Status == 'success') {
                                    this.postgetList(this.page);
                                } else {
                                    this.$message({
                                        type: 'error',
                                        message: '操作失败'
                                    });
                                }
                            })
                            // $.ajax({
                            //     headers: requestHeaders(),
                            //     url: `${mh}/generalBusiness/generalSave`,
                            //     method: "post",
                            //     data: {
                            //         Data: JSON.stringify(lJSONObject_DataSet),
                            //     },
                            //     success: (res) => {
                            //         if (res.Status == 'success') {
                            //             this.postgetList(this.page);
                            //         } else {
                            //             this.$message({
                            //                 type: 'error',
                            //                 message: '操作失败'
                            //             });
                            //         }
                            //     },
                            //     complete: (XMLHttpRequest) => {

                            //         requestPretreatment(XMLHttpRequest);
                            //     }
                            // });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '操作失败'
                            });
                        }

                    },
                    complete: (XMLHttpRequest) => {

                        requestPretreatment(XMLHttpRequest);
                    }
                });
            }).catch(() => { });
        },
        handle2(row) {
            this.$confirm('是否' + (row.Is_Sticky == '0' ? '置顶' : '取消置顶') + '该数据', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                let { TableName, primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                    method: "post",
                    data: {
                        Data: TableName,
                        Condition: primary_key + "='" + row[primary_key] + "'"
                    },
                    success: (res) => {
                        if (res.length == 1) {
                            res[0].Is_Sticky = (row.Is_Sticky == '0' ? '1' : '0');
                            let lJSONObject_DataSet = new Object();
                            let lJSONObject_Table = new Object();
                            lJSONObject_Table[TableName] = res;
                            lJSONObject_DataSet['Modify'] = lJSONObject_Table;
                            let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                            if (!lJSONObject_DataSet['Add']) {
                                lJSONObject_DataSet['Add'] = new Object();
                            }
                            lJSONObject_DataSet['Add']['base_operation_log'] = [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main,
                                Operation_Interface: "generalSave",
                                Operation_IP: getIpAddress()
                            }]
                            submitSave(lJSONObject_DataSet,(res)=>{
                                if (res.Status == 'success') {
                                    this.postgetList(this.page);
                                } else {
                                    this.$message({
                                        type: 'error',
                                        message: '操作失败'
                                    });
                                }
                            })
                            // $.ajax({
                            //     headers: requestHeaders(),
                            //     url: `${mh}/generalBusiness/generalSave`,
                            //     method: "post",
                            //     data: {
                            //         Data: JSON.stringify(lJSONObject_DataSet),
                            //     },
                            //     success: (res) => {
                            //         if (res.Status == 'success') {
                            //             this.postgetList(this.page);
                            //         } else {
                            //             this.$message({
                            //                 type: 'error',
                            //                 message: '操作失败'
                            //             });
                            //         }
                            //     },
                            //     complete: (XMLHttpRequest) => {

                            //         requestPretreatment(XMLHttpRequest);
                            //     }
                            // });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '操作失败'
                            });
                        }

                    }, complete: (XMLHttpRequest) => {

                        requestPretreatment(XMLHttpRequest);
                    }
                });
            }).catch(() => { });
        },
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
